<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\CarBook;

class CarBookDao extends BaseDao
{
    protected function setModel(): string
    {
        return CarBook::class;
    }

    /**
     * 列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @return array
     */
    public function getList(array $where = [],int $page = 1,int $limit = 0){
        $model = $this->getModel()->alias('a')->where(['a.is_del'=>0]);
        $model = $model->field('a.*');
        $model = $this->setWheres($model,$where);
        $count = $model->count();
        $list = $model->order('a.id desc')->page($page,$limit)->select()->toArray();
        return compact('list','count');
    }

    /**
     * 搜索条件
     * @param $model
     * @param $where
     * @return mixed
     */
    public function setWheres($model,$where){
        if(isset($where['keyword']) && $where['keyword']){
            $model->where('a.car_type_name|a.contact_name|a.contact_mobile','like',"%{$where['keyword']}%");
        }
        if($where['status']!==''){
            $model->where('a.status','=',$where['status']);
        }
        return $model;
    }
}
